package com.zhangln.mountbuzhou.config;

import com.zhangln.mountbuzhou.dao.TbConnectionLogDao;
import com.zhangln.mountbuzhou.dao.TbOnlineDao;
import com.zhangln.mountbuzhou.dao.TbPushLogDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author sherry
 * @description
 * @date Create in 2020/5/3
 * @modified By:
 */
@Component
public class BuzhouInit implements CommandLineRunner, Ordered {
    @Value("${spring.profiles.active:prod}")
    private String active;
    @Autowired
    private TbConnectionLogDao tbConnectionLogDao;
    @Autowired
    private TbOnlineDao tbOnlineDao;
    @Autowired
    private TbPushLogDao tbPushLogDao;

    @Override
    public void run(String... args) throws Exception {
//        判断当前环境，如果是dev，则清理日志
        if (Objects.equals(active, "dev")) {
            tbConnectionLogDao.truncate();
            tbOnlineDao.truncate();
            tbPushLogDao.truncate();
        }
    }

    @Override
    public int getOrder() {
        return 1;
    }
}
